package com.mach.platform.utils;

import org.joda.time.DateTime;

import java.text.DecimalFormat;
import java.util.*;

/**
 * @author Administrator
 * @Description:   临时数据方法
 * @Package: com.ems.util
 * @Time create on 2017/11/29 15:03
 */
public class TempMethods {

	/**
	 * 生成24小时 数据，累计的
	 * @return
	 */
	public static List<Map> generate24HourDatas() {

		List<Map> result = new ArrayList<>();

		Map resultMap = new HashMap();
		//24小时横轴锚点
		List<Map> anchor = new ArrayList<>();

		DateTime dateTime = new DateTime();

		//结束时间
		String eTime = dateTime.toString("yyyy-MM-dd HH:mm:ss");

		String sTime = dateTime.toString("yyyy-MM-dd");
		DateTime dateTime2 = DateTime.parse(sTime);
		dateTime2 = dateTime2.plusMinutes(1);

		Integer data = 0;

		while (dateTime2.isBefore(dateTime)) {

			String time = dateTime2.toString("yyyy-MM-dd HH:mm:ss");
			Map tempMap = new HashMap(2);
			tempMap.put("name", time);
			if (data == 0) {
				data = generateInteger();
			} else {
				data = data + generateInteger();
			}

			tempMap.put("value", new Object[] { time, data });

			result.add(tempMap);

			dateTime2 = dateTime2.plusMinutes(1);

		}

		return result;

	}

	/**
	 * 生成24小时 数据，单个时间单个值
	 *
	 * @return
	 */
	public static List<Map> generate24HourDatas2(Integer times,Integer flag) {

		List<Map> result = new ArrayList<>();

		if (flag == 0) {

			Map resultMap = new HashMap();
			//24小时横轴锚点
			List<Map> anchor = new ArrayList<>();

			DateTime dateTime = new DateTime();

			//结束时间
			String eTime = dateTime.toString("yyyy-MM-dd HH:mm:ss");

			String sTime = dateTime.toString("yyyy-MM-dd");
			DateTime dateTime2 = DateTime.parse(sTime);
			dateTime2 = dateTime2.plusMinutes(1);

			Integer data = 0;

			while (dateTime2.isBefore(dateTime)) {

				String time = dateTime2.toString("yyyy-MM-dd HH:mm:ss");
				Map tempMap = new HashMap(2);
				tempMap.put("name", time);

				tempMap.put("value", new Object[] { time, generateInteger2(times) });

				result.add(tempMap);

				dateTime2 = dateTime2.plusMinutes(1);

			}


		}else {

			DateTime dateTime = new DateTime();
			Map tempMap = new HashMap(2);
			tempMap.put("name", dateTime.toString("yyyy-MM-dd HH:mm:ss"));

			tempMap.put("value", new Object[] { dateTime.toString("yyyy-MM-dd HH:mm:ss"), generateInteger2(times) });
			result.add(tempMap);

		}





		return result;

	}

	/**
	 * 生成24小时温度 虚拟数据
	 * @param flag
	 * @return
	 */
	public static List<Map> generate24HourDatas3(Integer flag) {

		List<Map> result = new ArrayList<>();

		if (flag == 0) {

			Map resultMap = new HashMap();
			//24小时横轴锚点
			List<Map> anchor = new ArrayList<>();

			DateTime dateTime = new DateTime();

			//结束时间
			String eTime = dateTime.toString("yyyy-MM-dd HH:mm:ss");

			String sTime = dateTime.toString("yyyy-MM-dd");
			DateTime dateTime2 = DateTime.parse(sTime);
			dateTime2 = dateTime2.plusMinutes(1);

			Integer data = 0;

			while (dateTime2.isBefore(dateTime)) {

				String time = dateTime2.toString("yyyy-MM-dd HH:mm:ss");
				Map tempMap = new HashMap(2);
				tempMap.put("name", time);

				tempMap.put("value", new Object[] { time, generateInteger3() });

				result.add(tempMap);

				dateTime2 = dateTime2.plusMinutes(5);

			}

		} else {

			DateTime dateTime = new DateTime();
			Map tempMap = new HashMap(2);
			tempMap.put("name", dateTime.toString("yyyy-MM-dd HH:mm:ss"));

			tempMap.put("value", new Object[] { dateTime.toString("yyyy-MM-dd HH:mm:ss"), generateInteger3() });
			result.add(tempMap);

		}

		return result;

	}

	public static Integer generateInteger() {

		Random random = new Random();

		Integer result = 0;

		for (int i = 0; i < 60; i++) {
			 result = result+ (random.nextInt(10) + 370);
		}

		return result;

	}

	public static Integer generateInteger3() {

		Random random = new Random();


		return (12-random.nextInt(10));

	}

	public static Integer generateInteger2(Integer time) {

		Random random = new Random();

		Integer result = 0;

		for (int i = 0; i < time; i++) {
			result = result + (random.nextInt(100) + 300);
		}


		return result;

	}


//	冷冻水生成虚拟数据

	/**
	 * 生成24小时温度 虚拟数据
	 *
	 * @param flag
	 * @return
	 */
	public static List<Map> generate24HourColdWaters(Integer flag) {

		List<Map> result = new ArrayList<>();

		Random random = new Random();
		DecimalFormat formatter = new DecimalFormat("#.#");
		if (flag == 0) {

			Map resultMap = new HashMap();
			//24小时横轴锚点
			List<Map> anchor = new ArrayList<>();

			DateTime dateTime = new DateTime();

			//结束时间
			String eTime = dateTime.toString("yyyy-MM-dd HH:mm:ss");

			String sTime = dateTime.toString("yyyy-MM-dd");
			DateTime dateTime2 = DateTime.parse(sTime);
			dateTime2 = dateTime2.plusMinutes(1);

			Integer data = 0;

			while (dateTime2.isBefore(dateTime)) {

				String time = dateTime2.toString("yyyy-MM-dd HH:mm:ss");
				Map tempMap = new HashMap(2);
				tempMap.put("name", time);

				tempMap.put("value", new Object[] { time,
						Double.parseDouble(formatter.format(random.nextDouble() + 9 + random.nextInt(3)))});

				result.add(tempMap);

				dateTime2 = dateTime2.plusMinutes(1);

			}

		} else {

			DateTime dateTime = new DateTime();
			Map tempMap = new HashMap(2);
			tempMap.put("name", dateTime.toString("yyyy-MM-dd HH:mm:ss"));

			tempMap.put("value", new Object[] { dateTime.toString("yyyy-MM-dd HH:mm:ss"),
					Double.parseDouble(formatter.format(random.nextDouble() + 6 + random.nextInt(6))) });
			result.add(tempMap);

		}

		return result;

	}


}
